[?php use_helper('SEstadisticas') ?]
[?php echo_title('Historial de cambios') ?]
<div id="admin_container">
<h1>Historial de cambios de <?php echo $this->getReadableName() ?></h1>

  [?php include_partial('<?php echo $this->getModuleName() ?>/flashes') ?]

  <div id="admin_content">
<?php if (isset($this->params['route_column'])): ?>
  <form action="[?php echo url_for('<?php echo $this->getUrlForAction('collection')?>', array('action' => 'batchVersion', '<?php echo $this->params['route_column'] ?>' => $<?php echo $this->getSingularName(),'->',$this->params['route_column'] ?>)) ?]" method="post">
<?php else: ?>
  <form action="[?php echo url_for('<?php echo $this->getUrlForAction('collection')?>', array('action' => 'batchVersion')), '?id=', $<?php echo $this->getSingularName() ?>->id ?]" method="post">
<?php endif ?>
  <ul class="admin_actions">
  <li class="admin_batch_actions_choice">
    <select name="batch_action">
      <option value="">Seleccione una acción</option>
      <option value="batchDeleteVersion">Borrar</option>
    </select>
    [?php $form = new BaseForm(); if ($form->isCSRFProtected()): ?]
      <input type="hidden" name="[?php echo $form->getCSRFFieldName() ?]" value="[?php echo $form->getCSRFToken() ?]" />
    [?php endif; ?]
    <input type="submit" value="ok" />
  </li>
  </ul>
  <div class="admin_list">
    [?php if ($pager->getNbResults() == 0): ?]
      <p>Sin resultados</p>
    [?php else: ?]
      <table>
      <thead>
        <tr>
          <th id="admin_list_batch_actions">
            <input id="admin_list_batch_checkbox" type="checkbox" onclick="checkAll();">
          </th>
          <th>Versión</th>
          <th>Usuario</th>
          <th>Ip</th>
          <th>Fecha</th>
          <th id="admin_list_th_actions">Acciones</th>
        </tr>
      </thead>
      <tfoot>
        <tr>
          <th colspan="7">
            [?php if ($pager->haveToPaginate()) : ?]
              [?php include_partial('<?php echo $this->getModuleName() ?>/historic_pagination', array('pager' => $pager, 'id' => $<?php echo $this->getSingularName() ?>->getId())) ?]
            [?php endif; ?]
            [?php echo $pager->getNbResults(), ' ', $pager->getNbResults() == 1 ? 'resultado' : 'resultados' ?]
            [?php if ($pager->haveToPaginate()): ?]
              [?php printf('(página %s/%s)', $pager->getPage(), $pager->getLastPage()) ?]
            [?php endif; ?]
          </th>
        </tr>
      </tfoot>
      <tbody>
      [?php foreach($pager->getResults(Doctrine_Core::HYDRATE_ARRAY) as $version): ?]
        <tr> 
          <td><input class="admin_batch_checkbox" type="checkbox" value="[?php echo($version['version'])?]" name="versions[]"></td>
          <td class="admin_text">[?php echo $version['version'] ?]</td>
          <td class="admin_text">[?php echo $version['usuario'] ?]</td>
          <td class="admin_text">[?php echo $version['ip'] ?]</td>
          <td class="admin_text">[?php echo $version['fecha'] ?]</td>
          <td>
            [?php echo $helper->imgLinkToCompare($<?php echo $this->getSingularName() ?>, $version['version']) ?]
            [?php echo $helper->imgLinkToDeleteVersion($<?php echo $this->getSingularName() ?>, $version['version']) ?]
          </td>
        </tr>
      [?php endforeach; ?]
      </tbody>
      </table>
    [?php endif; ?]

    <ul class="admin_actions">
      [?php echo $helper->linkToShow($<?php echo $this->getSingularName() ?>, 'Volver a detalles') ?]
    </ul>
  </div>

  <script type="text/javascript">
  /* <![CDATA[ */

  function deleteVersion(element) {
    var data = {
      message: '¿Desea eliminar la versión seleccionada?',
      url: $(element).attr('href'),
      isCSRFProtected: [?php echo $form->isCSRFProtected() ? 'true' : 'false' ?],
      CSRFFieldName: '[?php echo $form->getCSRFFieldName()?]',
      CSRFToken: '[?php echo $form->getCSRFToken()?]',
      fieldName: 'version',
      fieldValue: $(element).attr('version')
    };

    createDeleteForm(data); //main.js

    return false; 
  }

  /* ]]> */
  </script>

  </form>
  </div>
</div>
